package org.classg.oss.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.classg.oss.service.OssService;
import org.classg.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

@Api(description = "阿里云文件管理")
@CrossOrigin// 跨域
@RestController
@RequestMapping("/ossservice/fileoss")
public class OssController {

    @Autowired
    private OssService ossService;

    /**
     * 头像文件上次
     */
    @ApiOperation("头像图片上传")
    @PostMapping
    public R uploadOssFile(@ApiParam(name = "file", value = "上传头像文件", required = true) MultipartFile file) {
        // 获取上传文件 MultipartFile
        // 返回上传到oss的路径
        String url = ossService.uploadFileAvatar(file);
        return R.ok().data("url", url);
    }

}
